package com.base.ui.other
{
	import com.base.Main;
	
	import flash.events.Event;
	
	import mx.containers.TitleWindow;
	import mx.controls.TextArea;
	import mx.core.Application;
	import mx.core.FlexGlobals;
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;
	
	public class StatusWindow extends TitleWindow
	{
		
		private static var _instance : StatusWindow;
		
		public static function get instance() : StatusWindow {
			if ( !_instance ) {
				_instance = new StatusWindow();
			}
			return _instance;
		}
		
		
		private var txt:TextArea;
		
		public function StatusWindow()
		{
			super();
			title="发送状态信息";
			width = 400;
			height = 300;
			layout="absolute" ;
			showCloseButton = true;
			txt = new TextArea();
			txt.verticalScrollPolicy = "auto";
			txt.percentWidth = 100;
			txt.percentHeight = 100;
			addChild( txt );
			addEventListener(CloseEvent.CLOSE , onCloseHandler );
		}
		
		protected function onCloseHandler( e:Event ):void {
			hide();
		}
		
		public static function addText( str:String ):void {
			var s:String =  instance.txt.text + "\n"+str;
			
			if( s.length > 500 ) {
				instance.txt.text = s.substr( s.length - 500 ); 
			} else {
				instance.txt.text = s;
			}
		}
		
		public static function show():void {
			instance.txt.verticalScrollPosition = instance.txt.maxVerticalScrollPosition;
			PopUpManager.addPopUp( instance , FlexGlobals.topLevelApplication as Application );
			PopUpManager.centerPopUp( instance );
		}
		
		public static function hide():void {
			PopUpManager.removePopUp( instance );
			Main.showStatusBtn();
			
		}
	}
}